package javabase.collection.list.listsort;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * <pre>
 *   Title: ListSortDemo001.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2013
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author liuzhaoqing
 * @version 1.0
 * @date 2014年11月5日
 */
class Person implements Comparable<Person> {
	
	private String name = null;
	private int age;
	
	public int compareTo(Person stu) {
		return age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "Person [name=" + name + ", age=" + age + "]";
	}

	@Override
	public int hashCode() {
		return super.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	@Override
	protected void finalize() throws Throwable {
		super.finalize();
	}
	
}

public class CollatorDemo001 {

	public static void main(String[] args) {
		List<String> strList = new ArrayList<String>();
		strList.add("上海");
		strList.add("重庆");
		strList.add("北京");
		strList.add("天津");
		strList.add("广州");
		strList.add("深圳");
		strList.add("苏州");
		strList.add("杭州");
		System.out.println("排序前：");
		for (int i = 0, size = strList.size(); i < size; i++) {
			System.out.println(strList.get(i));
		}
		// 最后一个字母的降序进行排列
		Collections.sort(strList);
		
		System.out.println("排序后：");
		for (int i = 0, size = strList.size(); i < size; i++) {
			System.out.println(strList.get(i));
		}
		System.out.println("---------------华丽的分割线-------------");
		Comparator<Object> comparator = Collator.getInstance(java.util.Locale.CHINA);
		Collator collator = null;
		if (comparator instanceof Collator) {
			collator = (Collator)comparator;
		}
		
		System.out.println(collator.getDecomposition());
		System.out.println(collator.getStrength());

		String[] strArray = new String [] {"上海", "北京", "重庆","天津", "广州", "深圳", "苏州", "杭州"};
		Arrays.sort(strArray, comparator);
		
		for (int i = 0, size = strArray.length; i < size; i++) {
			System.out.println(strArray[i]);
		}
	}

}
